home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / VSet2.0 / Src / vtesthi.c < prev   
Encoding:
C/C++ Source or Header  |  1992-04-20  |  3.3 KB  |  101 lines  |  [TEXT/????]

  1. /*
  2.     SAMPLE C PROGRAM
  3.  
  4.     HDF VSET 2.1
  5.     Jason Ng NCSA MAY 1991
  6.  
  7.     This program demonstrates the use of the high-level VSET write routines.
  8.     It shows how data can be stored in vdatas, and how vgroups can be created
  9.     from vdatas, vgroups and other HDF elements.
  10.  
  11.     This example creates a file "vtesthi.hdf" that may be viewed using the
  12.     vset utility "vshow".
  13.  
  14.     DETAILS
  15.  
  16.     This example shows how pressure data  and color data can be stored as a 
  17.     vset.  To store pressure data, a field named "PRES", is defined of 
  18.     float type. The routine VHstoredata() stores the pressure values in a vdata.
  19.  
  20.     Color data comprises 3 components (red, green, blue). These can be stored as
  21.     3 different fields in 3 vdatas. But this example shows that they can be
  22.     treated as ONE field, and stored together as a compound field called "COLOR".
  23.     The number of components of a field is called its order.  In this case, 
  24.     "COLOR" has order=3. (whereas "PRES" above has order=1).
  25.  
  26.     The routine VHstoredatam() must be used to store values of a compound field.
  27.     This is similar to VHstoredata() but has an extra argument for the order
  28.     to be specified.
  29.  
  30.     Finally a vgroup is created, and the ids of the created vdatas are stored
  31.     in the vgroup. This effectively groups the vdatas together. This example
  32.     also shows that you can insert another vgroup, as well as a non-vset element
  33.     (in this case, some element with tag=7777 and ref=1) into a vgroup.
  34. */
  35.  
  36. #include "vg.h"
  37.  
  38. #define fs "vtesthi.hdf"
  39. #define NP 100
  40. #define NC 60
  41. #define ORDERC 3 /* 3 color components: rgb */
  42.  
  43. main (ac,av)   int ac; char**av; {
  44.   int n = ac;
  45.  
  46.   printf("%s: tests high-level routines\n", av[0]);
  47.   printf("Creates 2 vdatas, a vgroup, and a non-vset element\n");
  48.   printf("then link them all into another vgroup\n");
  49.   printf("Vdata 1 contains an order-1 float field PRES\n");
  50.   printf("Vdata 2 contains an order-3  integer field COLOR\n\n");
  51.   printf("The non-vset element has tag=7777, ref=1\n");
  52.   doit();
  53.   printf("all done. created file %s\n", fs);
  54. }
  55.  
  56. /* ------------------------------------------------------------------ */
  57.  
  58. doit() {
  59. DF * f;
  60. float pvals[NP];
  61. int cvals[NC][ORDERC];
  62. int i,j;
  63.  
  64. int pid, cid; /* refs of vdatas */
  65. int eid; /* empty vgroup's ref  */
  66. int gid; /* vgroup's ref  */
  67. int tags[10], refs[10];
  68. char *CLS = "EXAMPLE";
  69.  
  70. /* --- generate data here --- */
  71.   for(i=0;i<NP;i++)  pvals[i] = 100.0  + i * 0.001;
  72.   for(i=0;i<NC;i++) for(j=0;j<3;j++)  cvals[i][j] =   i + j*100;
  73.  
  74.  
  75. /* ---- open a new file --- */
  76.  
  77. if (NULL==(f=DFopen(fs,DFACC_ALL,0))) { printf("open %s err\n",fs); exit(0); }
  78.  
  79. /* ---- create 2 vdatas --- */
  80. pid = VHstoredata (f, "PRES", (unsigned char*) pvals ,NP, LOCAL_FLOATTYPE, "pressure vals",CLS);
  81. if (pid  == -1) { printf(" VHstoredata store PRES err. "); }
  82.  
  83. cid  = VHstoredatam(f, "COLOR",(unsigned char*) cvals, NC, LOCAL_INTTYPE, "rgb colors", CLS, 3);
  84. if (cid  == -1) { printf(" VHstoredata store COLOR err. "); }
  85.  
  86. eid  = VHmakegroup (f, tags, refs, 0, "This is an EMPTY vgroup", CLS);
  87. if (eid  == -1) { printf(" VHmakegroup err\n"); }
  88.  
  89. /* --- create a new vgroup to store the 2 vdatas and the empty vgroup -- */
  90. tags[0] = VSDESCTAG;  refs[0] = pid;
  91. tags[1] = VSDESCTAG;  refs[1] = cid;
  92. tags[2] = VGDESCTAG;  refs[2] = eid;
  93. tags[3] = 7777 ;      refs[3] = 1;
  94.  
  95. gid  = VHmakegroup (f, tags, refs, 4, "here is a vset with 4 links", CLS);
  96. if (eid  == -1) { printf(" VHmakegroup err\n"); }
  97.  
  98. /* --- close the file --- */
  99. DFclose (f);
  100. }
  101.